package main

import (
	"flag"
	"github.com/dchest/jsmin"
	"io/ioutil"
	"os"
	"path/filepath"
)

var (
	filenameInput  string
	filenameOutput string
)

func init() {
	flag.StringVar(&filenameInput, "i", "in.js", "input filename")
	flag.StringVar(&filenameOutput, "o", "out.js", "output filename")
	flag.Parse()
}

func main() {
	w, err := os.Create(filenameOutput)
	if err != nil {
		panic(err)
	}
	defer w.Close()

	path, err := filepath.Abs(filenameInput)
	if err != nil {
		panic(err)
	}

	script, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err)
	}

	w.Write([]byte(`var _cvue=[];`))
	script, err = jsmin.Minify(cimport(w, path, script))
	if err != nil {
		panic(err)
	}
	w.Write(script)
}
